#!/bin/bash
#NFS 配置文件:/etc/exports 协议: NFS(2049) RPC(111) 服务: nfs-server
#查看服务器的共享 showmount -e IP
#客户端访问nfs需要安装nfs-utils
#开机挂载 IP:/public /mnt nfs defaults,_netdev 0 0
. ./public_functions #公共函数库

##1 安装nfs共享
nfs_Install() {

  if [[ ! $(rpm -q nfs-utils | grep not) ]]; then
    logTips "nfs-utils already installed" "(nfs-utils已存在)" #1-20#
    logY "rpm -qa | grep nfs-utils" #1-20#
    rpm -qa | grep nfs-utils --color
    echo
    exit
  fi 

  logW "1.安装依赖 rpcbind" #1-20#
  logY "yum install rpcbind -y" #1-20#
    yum install rpcbind -y
  checkTF #21#

  logW "2.启动 rpcbind 服务" #1-20#
  logY "systemctl enable --now  rpcbind" #1-20#
    systemctl enable --now  rpcbind
  checkTF #21#

  logW "3.安装 nfs-utils 软件" #1-20#
  logY "yum install nfs-utils -y" #1-20#
    yum install nfs-utils -y
  checkTF #21#

  logW "4.启动 nfs 服务" #1-20#
  logY "systemctl enable --now nfs" #1-20#
    systemctl enable --now nfs
  checkTF #21#

  logW "5.共享 /mnt 目录，书写配置文件" #1-20#
  logY "cat >/etc/exports << EOF..." #1-20#
cat >/etc/exports << EOF
/mnt     *(ro)
#/public 192.168.1.0(ro)
#/public 192.168.1.20(ro)
EOF
  checkTF #21#

  logW "6.重启 nfs 服务" #1-20#
  logY "systemctl restart nfs" #1-20#
    systemctl restart nfs
  checkTF #21#

  logW "7.查看共享" #1-20#
  logY "showmount -e 127.0.0.1" #1-20#
    showmount -e 127.0.0.1
  checkTF #21#

echo "提示：开机挂载请在/etc/fstab添加此格式内容: IP:/public /mnt nfs defaults,_netdev 0 0"
echo "tip: after booting up,Please add this format to /etc/fstab for mounting: IP:/public /mnt nfs defaults,_netdev 0 0"

}

nfs_Install ##1
